package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.MarketCollectExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketCollectMapper;
import com.cskaoyan.util.StringUtil;
import com.cskaoyan.util.TransactionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class CollectServiceImpl implements CollectService {
    @Override
    public CommonData<MarketCollect> query(Integer page, Integer limit, String sort, String order, Integer valueId, Integer userId) {
        MarketCollectExample example=new MarketCollectExample();
        MarketCollectExample.Criteria criteria = example.createCriteria();

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null) {
            criteria.andValueIdEqualTo(valueId);
        }

        criteria.andDeletedEqualTo(false);

        if (!StringUtil.isEmpty(sort) && !StringUtil.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        PageHelper.startPage(page, limit);


        MarketCollectMapper marketCollectMapper = TransactionUtil.getMapper(MarketCollectMapper.class);
        PageHelper.startPage(page, limit);
        List<MarketCollect> marketCollects= marketCollectMapper.selectByExample(example);
        return CommonData.data(new PageInfo(marketCollects));
    }
}
